using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace XcoAppSpaces.Transport.WCF
{
    /// <summary>
    /// Shutdown endpoint behavior
    /// </summary>
    public class XcoWCFEndpointBehavior : IEndpointBehavior
    {
        /// <summary>
        /// Interface for shutdown procedure
        /// </summary>
        public IXcoWCFTransportSessionShutdown Shutdown { get; set; }
        
        /// <summary>
        /// Create ShutdownBehavior instance
        /// </summary>
        /// <param name="shutdown">Interface for shutdown procedure</param>
        public XcoWCFEndpointBehavior(IXcoWCFTransportSessionShutdown shutdown)
        {
            this.Shutdown = shutdown;
        }
        /// <summary>
        /// Not used
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="bindingParameters"></param>
        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
        }
        /// <summary>
        /// Not used
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="clientRuntime"></param>
        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
        }
        /// <summary>
        /// Register shutdown behavior
        /// </summary>
        /// <param name="endpoint"></param>
        /// <param name="endpointDispatcher"></param>
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.DispatchRuntime.InputSessionShutdownHandlers.Add(new XcoWCFInputSessionShutdown(Shutdown));
        }

        /// <summary>
        /// Not used
        /// </summary>
        /// <param name="endpoint"></param>
        public void Validate(ServiceEndpoint endpoint)
        {
        }
    }
}